package com.example.fileupload.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 存储配置类 - 管理多种存储策略的配置
 */
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "storage")
public class StorageConfig {
    
    /**
     * 默认存储策略
     */
    private String strategy = "local";
    
    /**
     * 本地存储配置
     */
    private LocalConfig local = new LocalConfig();
    
    /**
     * MinIO存储配置
     */
    private MinioConfig minio = new MinioConfig();
    
    /**
     * OSS存储配置
     */
    private OssConfig oss = new OssConfig();
    
    // ============ Getter/Setter ============
    
    public String getStrategy() { return strategy; }
    public void setStrategy(String strategy) { this.strategy = strategy; }
    
    public LocalConfig getLocal() { return local; }
    public void setLocal(LocalConfig local) { this.local = local; }
    
    public MinioConfig getMinio() { return minio; }
    public void setMinio(MinioConfig minio) { this.minio = minio; }
    
    public OssConfig getOss() { return oss; }
    public void setOss(OssConfig oss) { this.oss = oss; }
    
    // ============ 内部配置类 ============
    
    /**
     * 本地存储配置
     */
    public static class LocalConfig {
        private String basePath = System.getProperty("user.home") + "/uploads/";
        
        public String getBasePath() { return basePath; }
        public void setBasePath(String basePath) { this.basePath = basePath; }
    }
    
    /**
     * MinIO存储配置
     */
    public static class MinioConfig {
        private boolean enabled = false;
        private String endpoint = "http://localhost:9000";
        private String accessKey = "minioadmin";
        private String secretKey = "minioadmin";
        private String bucketName = "fileupload";
        private int urlExpiry = 7;
        
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
        
        public String getAccessKey() { return accessKey; }
        public void setAccessKey(String accessKey) { this.accessKey = accessKey; }
        
        public String getSecretKey() { return secretKey; }
        public void setSecretKey(String secretKey) { this.secretKey = secretKey; }
        
        public String getBucketName() { return bucketName; }
        public void setBucketName(String bucketName) { this.bucketName = bucketName; }
        
        public int getUrlExpiry() { return urlExpiry; }
        public void setUrlExpiry(int urlExpiry) { this.urlExpiry = urlExpiry; }
    }
    
    /**
     * OSS存储配置
     */
    public static class OssConfig {
        private boolean enabled = false;
        private String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        private String accessKeyId = "";
        private String accessKeySecret = "";
        private String bucketName = "";
        private int urlExpiryHours = 24;
        
        public boolean isEnabled() { return enabled; }
        public void setEnabled(boolean enabled) { this.enabled = enabled; }
        
        public String getEndpoint() { return endpoint; }
        public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
        
        public String getAccessKeyId() { return accessKeyId; }
        public void setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; }
        
        public String getAccessKeySecret() { return accessKeySecret; }
        public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret = accessKeySecret; }
        
        public String getBucketName() { return bucketName; }
        public void setBucketName(String bucketName) { this.bucketName = bucketName; }
        
        public int getUrlExpiryHours() { return urlExpiryHours; }
        public void setUrlExpiryHours(int urlExpiryHours) { this.urlExpiryHours = urlExpiryHours; }
    }
} 